@isTest
private class ContractModifyControllerTest {
    static testMethod void testMethod1() {

    	 Account acc = TestUtils.createAccount();
        acc.Level__c = '三级甲等';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Dealer', 'Account');

        insert acc;     

        //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        insert opp;

        Id pRT = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');

     	Product__c p  = TestUtils.createInst();
        p.Name = '测试仪器';
        p.RecordTypeId = pRT;
        p.Category0__c  = '仪器';
        p.ProductName__c = '测试仪器';
        insert p ;





        Contract__c con = new Contract__c();
        con.Account__c = acc.Id;
        con.Opportunity__c = opp.Id;
       	con.Status__c  = '已生效';
        con.Corpcode__c = 'MKSY';
        con.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalContract', 'Contract__c');
        insert con;
   



          //报价2
        Quote qt2 = new Quote(Name = '试剂报价',Type__c = '试剂报价',OpportunityId = opp.Id,IsActive__c = true);
        qt2.Status = '已批准';
        qt2.Contract__c = con.Id;
        insert qt2 ;

        QuoteProduct__c qp = new QuoteProduct__c(Name = '测试报价产品2',Product__c = p.Id,Quote__c = qt2.Id,SalesPrice__c = 5);
        insert qp ;


        ContractProduct__c cp = new ContractProduct__c();
        cp.Contract__c = con.Id;
        cp.Product__c =p.Id  ;
        cp.Quantity__c = 1;
        cp.SalesPrice__c = 1; 
        cp.QuoteProduct__c = qp.Id;

        insert cp ;

        PageReference page = new PageReference('/apex/ContractModify?id=' + con.Id );
        System.Test.setCurrentPage(page);
        ContractModifyController  cmc = new ContractModifyController();

        cmc.init();

        //cmc.searchJson = EncodingUtil.urlEncode('{"ProductName__c":"测试"}', 'UTF-8');
        //cmc.searchProduct();



        List<ContractModifyController.ModifyBean>  cpList =new List<ContractModifyController.ModifyBean>();
        	ContractModifyController.ModifyBean cmb = new ContractModifyController.ModifyBean(cp);
        	cmb.changetype = '新增合同仪器';
        	cmb.adprice = 10;
        cpList.add(cmb);
        Map<String,Object> saveMap = new Map<String,Object>();
        saveMap.put('datas', cpList);


        Map<String,String> baseMap = new Map<String,String>();
        baseMap.put('ContractSource__c', '0');
        baseMap.put('Compensation__c', '0');
        saveMap.put('base', baseMap);
        cmc.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap), 'UTF-8');

        cmc.save();

       Contract__c changeCon =  [select Id from Contract__c where RecordType.DeveloperName = 'ChangeContract' limit 1 ];


       PageReference page1= new PageReference('/apex/ContractModify?id=' + changeCon.Id );
        System.Test.setCurrentPage(page1);
        ContractModifyController  cmc1 = new ContractModifyController();
        cmc1.init();




        
    }
}